package cn.highedu.coolsharkhub.controller;

import cn.highedu.coolsharkhub.entity.dto.BannerDTO;
import cn.highedu.coolsharkhub.entity.vo.BannerManagementVO;
import cn.highedu.coolsharkhub.service.BannerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图控制层
 */
@RestController
public class BannerController {
    Logger logger = LoggerFactory.getLogger(BannerController.class);

    @Autowired
    BannerService bannerService;

    @GetMapping("/banners/management")
    public List<BannerManagementVO> findAll() {
        logger.info("查询所有轮播图");
        return bannerService.findAll();
    }

    /**
     * 保存轮播图
     * @param bannerDTO 轮播图数据(轮播图路径, 播放顺序)
     * @return 保存结果
     */
    @PostMapping("/banners")
    @ResponseStatus(HttpStatus.CREATED) // 201
    public String addBanner(@RequestBody BannerDTO bannerDTO) {
        logger.info("保存轮播图");
        bannerService.addBanner(bannerDTO);
        return "保存成功";
    }
}
